import { Button,Input } from "antd";
import "./login.scss";
import { useNavigate  } from "react-router-dom";
import { login } from "../../api/login";
import { useState } from "react";
import config from '../../config'
function Login() {
  const navigate = useNavigate ()

  const [account] = useState()
  const [password] = useState()

  const logon = () => {
    login({
      account: account,
      password: password
    }).then(res => {
      if(res.data.token){
        localStorage.setItem(config.SESSION_INFO, res.data.token)
        navigate('/')
      }
    })
  }

  return (
    <div className="P-login">
        <h1>用户登录</h1>
        <div className="account">
            <Input placeholder="请输入账户" value={account}/>
        </div>
        <div className="password">
            <Input.Password placeholder="请输入密码" value={password}/>
        </div>
        <div className="login">
            <Button type="primary" onClick={logon}>登录</Button>
        </div>
    </div>
  );
}

export default Login;
